package com.zygh.policeasset.service;

import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.mapper.*;
import com.zygh.policeasset.pojo.*;
import com.zygh.policeasset.pojo.dto.UpdateBatchAssetsNumDTO;
import com.zygh.policeasset.pojo.imports.BasicsImport;
import com.zygh.policeasset.pojo.imports.DailyImport;
import com.zygh.policeasset.pojo.imports.HardwitImport;
import com.zygh.policeasset.pojo.imports.PurchaseImport;
import com.zygh.policeasset.pojo.imports.SoftwitImport;
import com.zygh.policeasset.pojo.vo.AssetsCardVO;
import com.zygh.policeasset.pojo.vo.AssetsQrCodeVO;
import com.zygh.policeasset.pojo.vo.BeyondTheAssets;
import com.zygh.policeasset.pojo.vo.MonthListVO;
import com.zygh.policeasset.utils.DepRateByTimeUtil;
import com.zygh.policeasset.utils.EasyExcelUtil;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.zygh.policeasset.utils.UuidUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;

@Service
@Validated
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/service/AssetsService.class */
public class AssetsService {
    @Autowired
    AssetsMapper assetsMapper;
    @Autowired
    NewApprovalProcessMapper newApprovalProcessMapper;
    @Autowired
    ApprovalStepsMapper approvalStepsMapper;
    @Autowired
    ProjectMapper projectMapper;
    @Autowired
    SettlementMapper settlementMapper;
    @Autowired
    DailyProjectMapper dailyProjectMapper;
    @Autowired
    AdjustAssetsCardMapper adjustAssetsCardMapper;
    @Autowired
    AssetsLifeCycleMapper assetsLifeCycleMapper;
    @Autowired
    AssetsImagesMapper assetsImagesMapper;
    @Autowired
    DictDataMapper dictDataMapper;
    @Autowired
    UnitMapper unitMapper;
    @Autowired
    WitbigMapper witbigMapper;
    @Autowired
    MinioService minioService;
    @Autowired
    WitsmallMapper witsmallMapper;
    @Autowired
    AssetDisposalMapper assetDisposalMapper;
    @Autowired
    EasyExcelUtil easyExcelUtil;
    @Autowired
    VisualSettingsMapper visualSettingsMapper;

    @Validated({BasicsImport.Create.class})
    public Integer addBasics(@Valid BasicsImport basicsImport) {
        return this.assetsMapper.addBasics(basicsImport);
    }

    @Validated({HardwitImport.Create.class})
    public Integer addHardwit(@Valid HardwitImport hardwitImport) {
        return this.assetsMapper.addHardwit(hardwitImport);
    }

    @Validated({SoftwitImport.Create.class})
    public Integer addSoftwit(@Valid SoftwitImport softwitImport) {
        return this.assetsMapper.addSoftwit(softwitImport);
    }

    @Validated({DailyImport.Create.class})
    public Integer addDaily(@Valid DailyImport dailyImport) {
        System.out.println(dailyImport);
        return this.assetsMapper.addDaily(dailyImport);
    }

    @Validated({PurchaseImport.Create.class})
    public Integer addPurchase(@Valid PurchaseImport purchaseImport) {
        return this.assetsMapper.addPurchase(purchaseImport);
    }

    public Integer add(Object obj) {
        ObjectMapper objectMapper = new ObjectMapper();
        JSONObject jsonObject = (JSONObject) objectMapper.convertValue(obj, JSONObject.class);
        int count = 0;
        if ("jc".equals(jsonObject.getString("assetsType"))) {
            BasicsImport basicsImport = (BasicsImport) objectMapper.convertValue(obj, BasicsImport.class);
            basicsImport.setDeviceType("jc");
            basicsImport.setAssetsTypeName("基础");
            basicsImport.setAssetsStatusName("新增");
            basicsImport.setAssetDisposalName("正常");
            basicsImport.setBigName(this.witbigMapper.findOneByNum("jc", basicsImport.getBigNum()));
            basicsImport.setSmallName(this.witsmallMapper.findOneByNum("jc", basicsImport.getBigNum(), basicsImport.getSmallNum()));
            basicsImport.setConstrucUnitName(this.unitMapper.findOneByNum("zd", basicsImport.getConstrucUnit()));
            basicsImport.setBuildUnitName(this.unitMapper.findOneByNum("jc", basicsImport.getBuildNum()));
            basicsImport.setCreateTime(DateUtil.now());
            count = this.assetsMapper.addBasics(basicsImport);
            this.assetsLifeCycleMapper.add(basicsImport.getId(), 1, DateUtil.now(), Integer.valueOf(Integer.parseInt(basicsImport.getUserId())));
        } else if ("znh".equals(jsonObject.getString("assetsType"))) {
            HardwitImport hardwitImport = (HardwitImport) objectMapper.convertValue(obj, HardwitImport.class);
            hardwitImport.setDeviceType("zn");
            hardwitImport.setAssetsTypeName("智能硬件");
            hardwitImport.setAssetsStatusName("新增");
            hardwitImport.setAssetDisposalName("正常");
            hardwitImport.setBigName(this.witbigMapper.findOneByNum("zn", hardwitImport.getBigNum()));
            hardwitImport.setSmallName(this.witsmallMapper.findOneByNum("zn", hardwitImport.getBigNum(), hardwitImport.getSmallNum()));
            hardwitImport.setConstrucUnitName(this.unitMapper.findOneByNum("zd", hardwitImport.getConstrucUnit()));
            hardwitImport.setBuildUnitName(this.unitMapper.findOneByNum("zn", hardwitImport.getBuildNum()));
            hardwitImport.setMaintainUnitName(this.unitMapper.findOneByNum("zn", hardwitImport.getMaintainUnit()));
            hardwitImport.setCreateTime(DateUtil.now());
            count = this.assetsMapper.addHardwit(hardwitImport);
            this.assetsLifeCycleMapper.add(hardwitImport.getId(), 1, DateUtil.now(), Integer.valueOf(Integer.parseInt(hardwitImport.getUserId())));
        } else if ("zns".equals(jsonObject.getString("assetsType"))) {
            SoftwitImport softwitImport = (SoftwitImport) objectMapper.convertValue(obj, SoftwitImport.class);
            softwitImport.setDeviceType("zn");
            softwitImport.setAssetsTypeName("智能软件");
            softwitImport.setAssetsStatusName("新增");
            softwitImport.setAssetDisposalName("正常");
            softwitImport.setBigName(this.witbigMapper.findOneByNum("zn", softwitImport.getBigNum()));
            softwitImport.setSmallName(this.witsmallMapper.findOneByNum("zn", softwitImport.getBigNum(), softwitImport.getSmallNum()));
            softwitImport.setConstrucUnitName(this.unitMapper.findOneByNum("zd", softwitImport.getConstrucUnit()));
            softwitImport.setBuildUnitName(this.unitMapper.findOneByNum("zn", softwitImport.getBuildNum()));
            softwitImport.setMaintainUnitName(this.unitMapper.findOneByNum("zn", softwitImport.getMaintainUnit()));
            softwitImport.setCreateTime(DateUtil.now());
            count = this.assetsMapper.addSoftwit(softwitImport);
            this.assetsLifeCycleMapper.add(softwitImport.getId(), 1, DateUtil.now(), Integer.valueOf(Integer.parseInt(softwitImport.getUserId())));
        } else if ("da".equals(jsonObject.getString("assetsType"))) {
            DailyImport dailyImport = (DailyImport) objectMapper.convertValue(obj, DailyImport.class);
            dailyImport.setCreateTime(DateUtil.now());
            dailyImport.setAssetsTypeName("日常");
            dailyImport.setAssetsStatusName("新增");
            dailyImport.setAssetDisposalName("正常");
            dailyImport.setBigName(this.witbigMapper.findOneByNum(jsonObject.getString("deviceType"), dailyImport.getBigNum()));
            dailyImport.setSmallName(this.witsmallMapper.findOneByNum(jsonObject.getString("deviceType"), dailyImport.getBigNum(), dailyImport.getSmallNum()));
            dailyImport.setConstrucUnitName(this.unitMapper.findOneByNum("zd", dailyImport.getConstrucUnit()));
            dailyImport.setBuildUnitName(this.unitMapper.findOneByNum(jsonObject.getString("deviceType"), dailyImport.getBuildNum()));
            count = this.assetsMapper.addDaily(dailyImport);
            this.assetsLifeCycleMapper.add(dailyImport.getId(), 1, DateUtil.now(), Integer.valueOf(Integer.parseInt(dailyImport.getUserId())));
        } else if ("cg".equals(jsonObject.getString("assetsType"))) {
            PurchaseImport purchaseImport = (PurchaseImport) objectMapper.convertValue(obj, PurchaseImport.class);
            purchaseImport.setCreateTime(DateUtil.now());
            purchaseImport.setAssetsTypeName("采购");
            purchaseImport.setAssetsStatusName("新增");
            purchaseImport.setAssetDisposalName("正常");
            count = this.assetsMapper.addPurchase(purchaseImport);
            this.assetsLifeCycleMapper.add(purchaseImport.getId(), 1, DateUtil.now(), Integer.valueOf(Integer.parseInt(purchaseImport.getUserId())));
        }
        return count;
    }

    public Integer updateById(Assets assets) {
        if (!StringUtils.isEmpty(assets.getBigNum())) {
            assets.setWitbigName(this.witbigMapper.findOneByNum(assets.getDeviceType(), assets.getBigNum()));
        }
        if (!StringUtils.isEmpty(assets.getSmallNum())) {
            assets.setWitsmallName(this.witsmallMapper.findOneByNum(assets.getDeviceType(), assets.getBigNum(), assets.getSmallNum()));
        }
        if (!StringUtils.isEmpty(assets.getConstrucUnit())) {
            assets.setConstrucUnitName(this.unitMapper.findOneByNum("zd", assets.getConstrucUnit()));
        }
        if (!StringUtils.isEmpty(assets.getBuildNum())) {
            assets.setBuildUnitName(this.unitMapper.findOneByNum(assets.getDeviceType(), assets.getBuildNum()));
        }
        if (!StringUtils.isEmpty(assets.getMaintainUnit())) {
            assets.setMaintainUnitName(this.witbigMapper.findOneByNum(assets.getDeviceType(), assets.getMaintainUnit()));
        }
        if ("jc".equals(assets.getAssetsType())) {
            assets.setAssetsTypeName("基础");
        } else if ("zns".equals(assets.getAssetsType())) {
            assets.setAssetsTypeName("智能软件");
        } else if ("znh".equals(assets.getAssetsType())) {
            assets.setAssetsTypeName("智能硬件");
        } else if ("da".equals(assets.getAssetsType())) {
            assets.setAssetsTypeName("日常");
        } else if ("cg".equals(assets.getAssetsType())) {
            assets.setAssetsTypeName("采购");
        }
        if (!StringUtils.isEmpty(assets.getAssetsStatus())) {
            assets.setAssetsStatusName(this.dictDataMapper.findBydictTypeAndValue("assetsStatus", assets.getAssetsStatus().toString()).getDictName());
        }
        if (!StringUtils.isEmpty(assets.getAssetDisposal())) {
            assets.setAssetDisposalName(this.dictDataMapper.findBydictTypeAndValue("asset_disposal", assets.getAssetDisposal().toString()).getDictName());
        }
        return Integer.valueOf(this.assetsMapper.updateById(assets));
    }

    public PageInfo findAll(int pageNum, int pageSize, Assets assets) {
        PageInfo<Assets> source = PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() ->
                this.assetsMapper.findAll(assets));
        PageInfo<Assets> target = new PageInfo();
        BeanUtils.copyProperties(source, target);
        List<Assets> list = tolist(source.getList());
        target.setList(list);
        return target;
    }

    public List<Assets> tolist(List<Assets> list) {
        for (Assets a : list) {
            if (a.getWhetherEnable().intValue() == 0) {
                a.setWhetherEnableName("未启用");
            } else {
                a.setWhetherEnableName("已启用");
            }
        }
        return list;
    }

    public PageInfo beyondThe(int pageNum, int pageSize, Assets assets) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo(this.assetsMapper.beyondThe(assets));
    }

    public List<BeyondTheAssets> pushBeyondTheAssets() {
        return this.assetsMapper.pushBeyondTheAssets();
    }

    @Transactional
    public CommonResult bindingCards(BindingCards bindingCards) {

        String qrcode = assetsMapper.getQrCode(bindingCards.getAssetId());
        if (!StringUtils.isEmpty(qrcode)) {
            return new CommonResult().validateFailed("此资产已绑定二维码");
        }

        Integer count = assetsMapper.bindingCards(bindingCards.getQrCode(),
                bindingCards.getAssetId(),DateUtil.now());

        if (!StringUtils.isEmpty(bindingCards.getConnect())) {
            Integer count1 = assetsImagesMapper.updateByAssetId(bindingCards.getAssetId(),
                    bindingCards.getConnect());
            if (count1 == 0) {
                Integer count2 = assetsImagesMapper.add(bindingCards.getAssetId(), bindingCards.getConnect(),
                        DateUtil.now());
            }
        }

        if (count > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("二维码绑定失败");
    }

    public CommonResult generateCode(String ids) {

        String[] strings = ids.split(",");
        Integer count = 0;

        String time = DateUtil.now();

        for (int i = 0; i < strings.length; i++) {
            String qcCode = assetsMapper.getQrCode(Integer.parseInt(strings[i]));
            if (!StringUtils.isEmpty(qcCode)) {
                return new CommonResult().validateFailed("选择中的资产中有已生成过二维码的资产");
            }
        }
        for (int i = 0; i < strings.length; i++) {
            assetsMapper.generateCode(UuidUtil.get12UUID(),
                    Integer.parseInt(strings[i]),
                    time, 1);
            count++;
        }
        if (count > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("二维码生成失败");
    }

    public AssetsQrCodeVO selectByQrCode(String qrCode) {

        AssetsQrCodeVO assets = assetsMapper.selectByQrCode(qrCode);
        System.out.println(assets);
        if (!StringUtils.isEmpty(assets)) {
            AssetsImages assetsImages = assetsImagesMapper.findByAssetsId(assets.getId());
            if (!StringUtils.isEmpty(assetsImages)) {
                assets.setImageUrl(assetsImages.getConnect());
            }
        }

        return assets;
    }

    public String findAllExport(HttpServletResponse response, Assets assets) {
        return this.easyExcelUtil.findAllExport(response, this.assetsMapper.findAll(assets));
    }

    public List<Assets> findAllNoPage(Assets assets) {
        return this.assetsMapper.findAll(assets);
    }

    public List<AssetsCardVO> assetsCardQuery(String assetIds) {
        List<AssetsCardVO> assetsCardVOList = new ArrayList<>();
        for (String i : assetIds.split(",")) {
            AssetsCard assetsCard = this.assetsMapper.assetsCardQuery(Integer.valueOf(Integer.parseInt(i)));
            AssetsCardVO assetsCardVO = new AssetsCardVO();
            BeanUtils.copyProperties(assetsCard, assetsCardVO);
            if ("jc".equals(assetsCard.getAssetsType())) {
                assetsCardVO.setCategoryName("基础交通");
                assetsCardVO.setAssetTypeName(assetsCard.getWitbigName() + "/" + assetsCard.getWitsmallName());
            } else if ("znh".equals(assetsCard.getAssetsType())) {
                assetsCardVO.setCategoryName("智能交通");
                assetsCardVO.setAssetTypeName(assetsCard.getWitbigName() + "/" + assetsCard.getWitsmallName());
            } else if ("zns".equals(assetsCard.getAssetsType())) {
                assetsCardVO.setCategoryName("智能交通");
                assetsCardVO.setAssetTypeName(assetsCard.getWitbigName() + "/" + assetsCard.getWitsmallName());
            } else if ("da".equals(assetsCard.getAssetsType())) {
                assetsCardVO.setCategoryName("基础交通");
                assetsCardVO.setAssetTypeName(assetsCard.getWitbigName() + "/" + assetsCard.getWitsmallName());
            } else if ("cg".equals(assetsCard.getAssetsType())) {
                assetsCardVO.setCategoryName("采购资产");
                assetsCardVO.setConstrucUnitName(assetsCard.getUseDepartment());
                assetsCardVO.setAssetTypeName(assetsCard.getAssetTypeNameCg());
                assetsCardVO.setBuildUnitName(assetsCard.getManufacturer());
            }
            assetsCardVOList.add(assetsCardVO);
        }
        return assetsCardVOList;
    }

    public Integer updateStartProvisionDate(String startProvisionDate, String certificateNum, String buildNum, Integer sectionId) {
        return this.assetsMapper.updateStartProvisionDate(startProvisionDate, certificateNum, buildNum, sectionId);
    }

    public Integer updAssetsClassificationId(String ids, Integer assetsClassificationId, Integer assetsClassificationPid) {
        Integer count = 0;
        for (String s : ids.split(",")) {
            count = Integer.valueOf(count.intValue() + this.assetsMapper.updAssetsClassificationId(s, assetsClassificationId, assetsClassificationPid).intValue());
        }
        return count;
    }

    public Assets findById(Integer id) {
        return this.assetsMapper.findById(id);
    }

    public List<Assets> findByIds(String[] id) {
        return this.assetsMapper.findByIds(id);
    }

    public List<Assets> findByProject(String buildNum, Integer sectionId, String name, Integer assetsClassificationId, String assetsType) {
        return this.assetsMapper.findByProject(buildNum, sectionId, name, assetsClassificationId, assetsType);
    }

    public List<DepRate> depRateStatistics(String startTime, String endTime, String time1, String time2, Integer condition, Integer dataLabelsId, Integer assetsClassificationId, Integer assetsClassificationPid) throws ParseException, IllegalAccessException {
        return new DepRateByTimeUtil().getDepRateNew(this.assetsMapper.depRateStatistics(startTime, endTime, dataLabelsId, assetsClassificationId, assetsClassificationPid), time1, time2, condition);
    }

    public Integer checkSubmitted(NewApprovalProcess newApprovalProcess) {
        int count = 0;
        if ("jc".equals(newApprovalProcess.getType()) || "zn".equals(newApprovalProcess.getType())) {
            count = this.settlementMapper.check(newApprovalProcess.getBuildNum(), newApprovalProcess.getSectionId());
        } else if ("cg".equals(newApprovalProcess.getType())) {
            count = this.projectMapper.check(newApprovalProcess.getBuildNum());
        } else if ("da".equals(newApprovalProcess.getType())) {
            count = this.dailyProjectMapper.check(Integer.valueOf(Integer.parseInt(newApprovalProcess.getBuildNum())));
        }
        return count;
    }

    public Integer checkNo(NewApprovalProcess newApprovalProcess) {
        Assets assets = new Assets();
        assets.setBuildNum(newApprovalProcess.getBuildNum());
        assets.setSectionId(newApprovalProcess.getSectionId());
        return Integer.valueOf(this.assetsMapper.findAll(assets).size());
    }

    @Transactional(rollbackFor = {Exception.class})
    public void assetsSubmit(NewApprovalProcess newApprovalProcess) {
        try {
            String approvedBy = this.approvalStepsMapper.approvedBy(newApprovalProcess.getType());
            if (!(approvedBy == null || approvedBy == "")) {
                newApprovalProcess.setUserId(Integer.valueOf(Integer.parseInt(approvedBy.split(",")[0])));
            }
            newApprovalProcess.setOperatingTime(DateUtil.now());
            newApprovalProcess.setApprovalStatus(1);
            this.newApprovalProcessMapper.add(newApprovalProcess);
            if ("jc".equals(newApprovalProcess.getType()) || "zn".equals(newApprovalProcess.getType())) {
                this.settlementMapper.updateZNJCAssetApprovalStatus(1, newApprovalProcess.getBuildNum(), newApprovalProcess.getSectionId());
            } else if ("cg".equals(newApprovalProcess.getType())) {
                this.projectMapper.updateCgAssetApprovalStatus(newApprovalProcess.getBuildNum(), 1);
            } else if ("da".equals(newApprovalProcess.getType())) {
                this.dailyProjectMapper.updateDaAssetApprovalStatus(Integer.valueOf(Integer.parseInt(newApprovalProcess.getBuildNum())), 1);
            }
            this.assetsMapper.updassetApprovalStatus(Integer.valueOf(StatusEnum.APPROVALING.getIndex()), newApprovalProcess.getBuildNum(), newApprovalProcess.getSectionId());
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
    }

    @Transactional(rollbackFor = {Exception.class})
    public void approve(NewApprovalProcess newApprovalProcess) {
        try {
            NewApprovalProcess newApprovalProcess1 = new NewApprovalProcess();
            if (1 == newApprovalProcess.getApprovalStatus().intValue()) {
                String[] users = this.approvalStepsMapper.approvedBy(newApprovalProcess.getType()).split(",");
                if (newApprovalProcess.getUserId().equals(Integer.valueOf(Integer.parseInt(users[users.length - 1])))) {
                    if ("jc".equals(newApprovalProcess.getType()) || "zn".equals(newApprovalProcess.getType())) {
                        this.settlementMapper.updateZNJCAssetApprovalStatus(Integer.valueOf(StatusEnum.ADOPT.getIndex()), newApprovalProcess.getBuildNum(), newApprovalProcess.getSectionId());
                        this.assetsMapper.updassetApprovalStatus(Integer.valueOf(StatusEnum.ADOPT.getIndex()), newApprovalProcess.getBuildNum(), newApprovalProcess.getSectionId());
                    } else if ("cg".equals(newApprovalProcess.getType()) || "zd".equals(newApprovalProcess.getType())) {
                        this.projectMapper.updateCgAssetApprovalStatus(newApprovalProcess.getBuildNum(), Integer.valueOf(StatusEnum.ADOPT.getIndex()));
                        this.assetsMapper.updassetApprovalStatus(Integer.valueOf(StatusEnum.ADOPT.getIndex()), newApprovalProcess.getBuildNum(), null);
                    } else if ("da".equals(newApprovalProcess.getType())) {
                        this.dailyProjectMapper.updateDaAssetApprovalStatus(Integer.valueOf(Integer.parseInt(newApprovalProcess.getBuildNum())), Integer.valueOf(StatusEnum.ADOPT.getIndex()));
                        this.assetsMapper.updassetApprovalStatus(Integer.valueOf(StatusEnum.ADOPT.getIndex()), newApprovalProcess.getBuildNum(), null);
                    }
                    newApprovalProcess.setOperatingTime(DateUtil.now());
                    newApprovalProcess.setApprovalStatus(Integer.valueOf(StatusEnum.ADOPT.getIndex()));
                    this.newApprovalProcessMapper.add(newApprovalProcess);
                } else {
                    int j = 0;
                    int i = 0;
                    while (true) {
                        if (i >= users.length) {
                            break;
                        } else if (users[i].equals(newApprovalProcess.getUserId())) {
                            j = i;
                            break;
                        } else {
                            i++;
                        }
                    }
                    newApprovalProcess1.setBuildNum(newApprovalProcess.getBuildNum());
                    newApprovalProcess1.setSectionId(newApprovalProcess.getSectionId());
                    newApprovalProcess1.setOperatingTime(DateUtil.now());
                    newApprovalProcess1.setUserId(Integer.valueOf(Integer.parseInt(users[j + 1])));
                    newApprovalProcess1.setApprovalStatus(Integer.valueOf(StatusEnum.APPROVALING.getIndex()));
                    this.newApprovalProcessMapper.add(newApprovalProcess1);
                }
            } else {
                newApprovalProcess.setOperatingTime(DateUtil.now());
                newApprovalProcess.setApprovalStatus(Integer.valueOf(StatusEnum.REFUSE.getIndex()));
                this.newApprovalProcessMapper.add(newApprovalProcess);
                if ("jc".equals(newApprovalProcess.getType()) || "zn".equals(newApprovalProcess.getType())) {
                    this.settlementMapper.updateZNJCAssetApprovalStatus(Integer.valueOf(StatusEnum.REFUSE.getIndex()), newApprovalProcess.getBuildNum(), newApprovalProcess.getSectionId());
                    this.assetsMapper.updassetApprovalStatus(Integer.valueOf(StatusEnum.REFUSE.getIndex()), newApprovalProcess.getBuildNum(), newApprovalProcess.getSectionId());
                } else if ("cg".equals(newApprovalProcess.getType()) || "zd".equals(newApprovalProcess.getType())) {
                    this.projectMapper.updateCgAssetApprovalStatus(newApprovalProcess.getBuildNum(), Integer.valueOf(StatusEnum.REFUSE.getIndex()));
                    this.assetsMapper.updassetApprovalStatus(Integer.valueOf(StatusEnum.REFUSE.getIndex()), newApprovalProcess.getBuildNum(), null);
                } else if ("da".equals(newApprovalProcess.getType())) {
                    this.dailyProjectMapper.updateDaAssetApprovalStatus(Integer.valueOf(Integer.parseInt(newApprovalProcess.getBuildNum())), Integer.valueOf(StatusEnum.REFUSE.getIndex()));
                    this.assetsMapper.updassetApprovalStatus(Integer.valueOf(StatusEnum.REFUSE.getIndex()), newApprovalProcess.getBuildNum(), null);
                }
            }
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
    }

    @Async("asyncTaskExecutor")
    public CompletableFuture<JSONObject> getTotal() {
        System.out.println("任务1：查询资产总数量......");
        if (this.assetsMapper.getTotal() != null) {
            return CompletableFuture.completedFuture(JSONObject.fromObject(this.assetsMapper.getTotal()));
        }
        return null;
    }

    @Async("asyncTaskExecutor")
    public CompletableFuture<JSONObject> getMonthTotal() {
        if (this.assetsMapper.getMonthTotal() != null) {
            return CompletableFuture.completedFuture(JSONObject.fromObject(this.assetsMapper.getMonthTotal()));
        }
        return null;
    }

    @Async("asyncTaskExecutor")
    public CompletableFuture<JSONArray> getAssetsSelfBuilt() {
        List<AssetsTypeSum> list = this.assetsMapper.getAssetsSelfBuilt();
        JSONArray jsonArray = new JSONArray();
        for (AssetsTypeSum assetsTypeSum : list) {
            JSONObject json = new JSONObject();
            if ("0".equals(assetsTypeSum.getName())) {
                json.put("name", "外接");
            }
            if ("1".equals(assetsTypeSum.getName())) {
                json.put("name", "自建");
            }
            jsonArray.add(json);
        }
        return CompletableFuture.completedFuture(jsonArray);
    }

    @Async("asyncTaskExecutor")
    public CompletableFuture<JSONArray> getAssetsLifeCycle() {
        List<AssetsTypeSum> list = this.assetsMapper.getAssetsLifeCycle();
        JSONArray jsonArray = new JSONArray();
        for (AssetsTypeSum assetsTypeSum : list) {
            JSONObject json = new JSONObject();
            json.put("name", assetsTypeSum.getName());
            json.put("value", assetsTypeSum.getNumberSum());
            jsonArray.add(json);
        }
        return CompletableFuture.completedFuture(jsonArray);
    }

    @Async("asyncTaskExecutor")
    public CompletableFuture<JSONArray> getAssetsTypeSumListOne() {
        JSONArray jsonArrayAll = new JSONArray();
        List<AssetsTypeSum> list = this.assetsMapper.getAssetsTypeSumListOne();
        JSONArray jsonArray = new JSONArray();
        for (AssetsTypeSum assetsTypeSum : list) {
            JSONObject json = new JSONObject();
            json.put("name", assetsTypeSum.getName());
            json.put("value", assetsTypeSum.getNumberSum());
            jsonArray.add(json);
        }
        JSONArray jsonArray1 = new JSONArray();
        for (AssetsTypeSum assetsTypeSum2 : list) {
            JSONObject json2 = new JSONObject();
            json2.put("name", assetsTypeSum2.getName());
            json2.put("value", Double.valueOf(assetsTypeSum2.getAmountSum()));
            jsonArray1.add(json2);
        }
        jsonArrayAll.add(jsonArray);
        jsonArrayAll.add(jsonArray1);
        return CompletableFuture.completedFuture(jsonArrayAll);
    }

    public PageInfo<MonthListVO> getMonthList(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(this.assetsMapper.getMonthList());
    }

    @Async("asyncTaskExecutor")
    public CompletableFuture<JSONArray> getAssetsTypeSumListTwo() {
        JSONArray jsonArrayAll = new JSONArray();
        List<AssetsTypeSum> list = this.assetsMapper.getAssetsTypeSumListTwo();
        JSONArray jsonArray = new JSONArray();
        for (AssetsTypeSum assetsTypeSum : list) {
            JSONObject json = new JSONObject();
            json.put("name", assetsTypeSum.getName());
            json.put("value", assetsTypeSum.getNumberSum());
            jsonArray.add(json);
        }
        JSONArray jsonArray1 = new JSONArray();
        for (AssetsTypeSum assetsTypeSum2 : list) {
            JSONObject json2 = new JSONObject();
            json2.put("name", assetsTypeSum2.getName());
            json2.put("value", Double.valueOf(assetsTypeSum2.getAmountSum()));
            jsonArray1.add(json2);
        }
        jsonArrayAll.add(jsonArray);
        jsonArrayAll.add(jsonArray1);
        return CompletableFuture.completedFuture(jsonArrayAll);
    }

    public CommonResult getAssetsTypeSumList() {
        VisualSettings visualSettings = this.visualSettingsMapper.queryByType("assets");
        List<AssetsTypeSum> list = this.assetsMapper.getAssetsTypeSum(visualSettings.getStartTime(), visualSettings.getEndTime());
        JSONArray jsonArray = new JSONArray();
        for (AssetsTypeSum assetsTypeSum : list) {
            JSONObject json = new JSONObject();
            if (Arrays.asList(visualSettings.getClassification().split(",")).contains(assetsTypeSum.getName())) {
                json.put("name", assetsTypeSum.getName());
                json.put("value", assetsTypeSum.getNumberSum());
                jsonArray.add(json);
            }
        }
        return new CommonResult().success(jsonArray);
    }

    public CommonResult lifeCycle() {
        VisualSettings visualSettings = this.visualSettingsMapper.queryByType("project");
        List<AssetsTypeSum> list = this.projectMapper.lifeCycle(visualSettings.getStartTime(), visualSettings.getEndTime());
        JSONArray jsonArray = new JSONArray();
        for (AssetsTypeSum assetsTypeSum : list) {
            JSONObject json = new JSONObject();
            if (Arrays.asList(visualSettings.getClassification().split(",")).contains(assetsTypeSum.getName())) {
                json.put("name", assetsTypeSum.getName());
                json.put("value", assetsTypeSum.getNumberSum());
                jsonArray.add(json);
            }
        }
        return new CommonResult().success(jsonArray);
    }

    public void updById(String assetIds, Integer userId) {
        String[] assetId = assetIds.split(",");
        for (String id : assetId) {
            Assets assets = new Assets();
            assets.setId(Integer.valueOf(Integer.parseInt(id)));
            assets.setAssetsStatus(-1);
            assets.setAssetsStatusName("作废");
            this.assetsMapper.updateById(assets);
            this.assetsLifeCycleMapper.add(Integer.valueOf(Integer.parseInt(id)), -1, DateUtil.now(), userId);
        }
    }

    public void updAssetsDisposal(String assetIds, Integer userId, Integer type) {
        String[] assetId = assetIds.split(",");
        for (String id : assetId) {
            Assets assets = new Assets();
            assets.setId(Integer.valueOf(Integer.parseInt(id)));
            assets.setAssetDisposal(type);
            assets.setAssetDisposalName(this.dictDataMapper.findBydictTypeAndValue("asset_disposal", type.toString()).getDictName());
            this.assetsMapper.updateById(assets);
            this.assetDisposalMapper.add(type, DateUtil.now(), userId, Integer.valueOf(Integer.parseInt(id)));
        }
    }

    public Double selectCombined(Integer whetherSet, String assetsType, String buildNum, String name, Integer sectionId, Integer assetsStatus) {
        return this.assetsMapper.selectCombined(whetherSet, assetsType, buildNum, name, sectionId, assetsStatus);
    }

    public Integer addLight(AddLightDto addLightDto) {
        int count = 0;
        for (String str : addLightDto.getIds().split(",")) {
            count = this.assetsMapper.updateById(new Assets().setId(Integer.valueOf(Integer.parseInt(str))).setLightGetBuildNum(addLightDto.getLightGetBuildNum()).setLightGetSectionId(addLightDto.getLightGetSectionId()));
        }
        return Integer.valueOf(count);
    }

    public Integer deleteLight(AddLightDto addLightDto) {
        int count = 0;
        for (String str : addLightDto.getIds().split(",")) {
            count = this.assetsMapper.deleteLight(Integer.valueOf(Integer.parseInt(str)));
        }
        return Integer.valueOf(count);
    }

    public Integer updateBatchAssetsNum(UpdateBatchAssetsNumDTO updateBatchAssetsNumDto) {
        return this.assetsMapper.updateBatchAssetsNum(updateBatchAssetsNumDto.getAssetsNum(), updateBatchAssetsNumDto.getIds().split(","));
    }

    public void breakUp(List<Assets> assets, String reason, Integer userId, Integer assetsId) {
        String str = "";
        for (Assets assets1 : assets) {
            assets1.setId(null);
            this.assetsMapper.add(assets1);
            str = str + assets1.getId() + ",";
        }
        AdjustAssetsCard adjustAssetsCard = new AdjustAssetsCard();
        adjustAssetsCard.setReason(reason);
        adjustAssetsCard.setUserId(userId);
        adjustAssetsCard.setType(3);
        adjustAssetsCard.setCreateTime(DateUtil.now());
        adjustAssetsCard.setAssetsIds(String.valueOf(assetsId));
        adjustAssetsCard.setBreakAssetsIds(str);
        this.adjustAssetsCardMapper.add(adjustAssetsCard);
        Assets assets2 = new Assets();
        assets2.setId(assetsId);
        assets2.setAssetsStatus(-1);
        assets2.setAssetsStatusName("作废");
        this.assetsMapper.updateById(assets2);
        this.assetsLifeCycleMapper.add(assetsId, -1, DateUtil.now(), userId);
    }

    @Transactional(rollbackFor = {Exception.class})
    public Integer deleteByIds(String ids) {
        try {
            Integer count = null;
            String[] strings = ids.split(",");
            for (String id : strings) {
                count = this.assetsMapper.deleteByIds(id);
                AssetsImages assetsImages = this.assetsImagesMapper.findByAssetsId(Integer.valueOf(Integer.parseInt(id)));
                if (assetsImages != null) {
                    this.assetsImagesMapper.deleteByAssetsId(Integer.valueOf(Integer.parseInt(id)));
                    this.minioService.removeObject("assets", assetsImages.getConnect().split("http://41.6.251.17:9000/assets/")[1]);
                }
            }
            return count;
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return 0;
        }
    }

    public List<String> discountChart(String type, Integer assetsStatus) {
        return this.assetsMapper.discountChart(type, assetsStatus);
    }

    public List<Company> columnar(String type, String type1) {
        return this.assetsMapper.columnar(type, type1);
    }
}